
$(document).on('pageinit', function(){
	$('#next').unbind();
	$('.year').unbind();
	$('.term').unbind();
	$('#userBanSubmit').unbind();
	
	var studentId = getCookie('studentId');
	if(studentId) $('#studentId').val(studentId);
	$('#next').on('tap', function(){
		var studentId = $('#studentId').val();
		if(/^\d{10}/.test(studentId)){
			setCookie('studentId', studentId);
			$.mobile.changePage( "./YearSelect.php", { transition: "slide"} );
		}else{
			$('#warningBtn').click();
		}
	});
	$('.year').on('tap', function(){
		var year = $(this).data('year');
		setCookie('year', year);
		$.mobile.changePage( "./TermSelect.php", { transition: "slide"} );
	});
	$('.term').on('tap', function(){
		var term = $(this).data('term');
		setCookie('term', term);
		window.location.href = './Grade.php';
	});
	$('#userBanSubmit').on('tap', function(){
		var studentId = $('#studentIdBan').val();
		var password = $('#passwordBan').val();
		if(!/^\d{10}/.test(studentId)){
			$('#warningBtn').click();
		}else{
			showLoader();
			$.ajax({
				url: './php/userBan.php',
				type: 'GET',
				data: '&studentId='+studentId+'&password='+password,
				dataType: "JSON",
				success:
					function(data){
						hideLoader();
						console.log(data);
						if(data.error){
							$('#warnText').text(data.error);
							$('#warningBtn').click();
						}else{
							$('#whereIsMyPassContent').html('<p>您的SecureID为：</p><p><b>'+data.secureid+'</b></p><p>请牢记，之后您&nbsp;<i>只能</i>&nbsp;通过该ID登陆查分！</p>');
						}
					}
			});
		}
	});
	$('#version').on('tap', function(){
		window.location.href = './updatelog.php';
	});
});